﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TtgProject.DAO;

namespace TtgProject.LOGIN
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          if(IsPostBack)
          {
              lblMessage.Text = "";
          }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string userName = txtUser.Text.Trim();
            string oldpass = txtOldPass.Text.Trim();
            string newpass = txtNewPass.Text.Trim();

            if (!String.IsNullOrEmpty(userName) && !String.IsNullOrEmpty(oldpass) && !String.IsNullOrEmpty(newpass))
            {
                TTGEntities ttgEntity = new TTGEntities();
                USER_TABLE usTable =
                    ttgEntity.USER_TABLE.SingleOrDefault(u => u.USER_ID.Equals(userName) && u.USER_PASSWORD.Equals(oldpass));
                if(usTable != null)
                {
                    usTable.USER_PASSWORD = newpass;
                    ttgEntity.SaveChanges();
                    lblMessage.Text = "Your Has been Changed ....";
                }
                
            }
            else
            {
                lblMessage.Text = "Invalid User Or Old Password Or New Password...Re-enter";
            }
            
        }
    }
}